package com.yspa.dbutil;

import java.sql.Connection;
import java.sql.DriverManager;

public class SQLServerConnection {
	 //SQLServer   
    private String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";//加载驱动程序  
    private String url = "jdbc:sqlserver://222.174.21.110:1433;DatabaseName=wkhm_c";//设置数据库连接串  
    private String user = "sa";//数据库登录用户名  
    private String password = "3Ik120";//数据库登录密码  
    private static String message = "恭喜，数据库连接正常！";  
    public void setDriverName(String newDriverName) {  
        driverName = newDriverName;  
    }  
    public String getDriverName() {  
        return driverName;  
    }  
      
    public void setUrl(String newUrl) {  
        url = newUrl;  
    }  
    public String getUrl() {  
        return url;  
    }  
    public void setUser(String newUser) {  
        user = newUser;  
    }  
    public String getUser() {  
        return user;  
    }  
    public void setPassword(String newPassword) {  
        password = newPassword;  
    }  
    public String getPassword() {  
        return password;  
    }  
    public Connection getConnection() {  
        try {  
            Class.forName(driverName);  
            return DriverManager.getConnection(url, user, password);  
        } catch (Exception e) {  
            e.printStackTrace();  
            message = "数据库连接失败！";  
            return null;  
        }  
    }  
    
    public static void main(String[] args) {  
        try{  
        	SQLServerConnection dcm = new SQLServerConnection();  
            Connection  conn = dcm.getConnection();  
            System.out.println(message);  
        }catch(Exception e){  
            e.printStackTrace();  
        }  
    }  
}
